<?php
/**
 * (actions) 提货申请（驳回）
 */
namespace App\Admin\Actions\Shipping;

use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
class SkuBatchReject extends BatchAction
{
    public $name = '驳回';

    public function handle(Collection $collection)
    {
        try{
            $count = 0;
            foreach ($collection as $model) {
                if($model->status != 2){ //待审批
                    continue;
                }
                $model->status = 3; //驳回
                $flag = $model->save();
                $flag && $count++;
            }
            return $this->response()->success("成功驳回{$count}条记录！")->refresh();
        }catch (\Exception $e){
            report($e);
            return $this->response()->error('系统异常！');
        }
    }
}
